package com.woniuxy.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class MyAspectJ {

    //前置通知
    public void myBefore(JoinPoint joinpoint){

        System.out.println("----------------------------------------");
        System.out.println("前置通知：日志打印开始……");
        System.out.println("对应目标类是："+joinpoint.getTarget());
        System.out.println("对应目标类的方法是："+joinpoint.getSignature().getName());
        System.out.println("----------------------------------------");
    }

    //后置通知
    public void afterReturing(JoinPoint joinpoint){
        System.out.println("----------------------------------------");
        System.out.println("后置通知：事务提交开始……");
        System.out.println("对应目标类是："+joinpoint.getTarget());
        System.out.println("对应目标类的方法是："+joinpoint.getSignature().getName());
        System.out.println("----------------------------------------");
    }
    //最终通知
    public void after(){
        System.out.println("----------------------------------------");
        System.out.println("最终通知执行，无论你的代码是否发生异常。");
        System.out.println("----------------------------------------");
    }
    //异常通知
    public void afterThrowing(Exception e){
        System.out.println("----------------------------------------");
        System.out.println("异常通知执行：报错类型是"+e.getMessage());
        System.out.println("----------------------------------------");
    }
    //环绕通知
//    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("环绕通知：前置通知……");
//        //目标方法的入参
//        Object[] args = joinPoint.getArgs();
//        for (Object arg : args) {
//            System.out.println(arg);
//        }
//        args[0] = 9;
//        args[1] = 10;
//        //环绕通知中，目标方法的执行
//        Object proceed = joinPoint.proceed(args);
//        System.out.println(proceed);
//        System.out.println("环绕通知：后置通知……");
//        return (int)proceed+1;
//    }
}
